<template>
	<view>
		<view v-show="key!=''">{{key}}的搜索结果</view>
		<view v-show="category!=''">{{category}}</view>
		<view v-if="goods.length!=0">
			<view v-for="(item,key) in goods" :key="key">
				<uni-list>
					<uni-list-item :thumb="item['goodspicture']" thumbSize="base">
						<template slot="body" class="temp" @tap="getClicked(item['goodsid'])">
							<text class="temp_text1">名称：{{item['goodsname']}}</text>
							<text class="temp_text2">价格：{{item['goodsprice']}}</text>
							<text class="temp_text3" v-if="userType===1">库存：{{item['goodsstock']}}</text>
							<text class="temp_text4">规格：{{item['goodsstandard']}}</text>
						</template>
					</uni-list-item>
				</uni-list>
			</view>
		</view>
		<view v-else>联系商家试试吧~</view>
	</view>
</template>

<script>
	import {mapState, mapMutations} from 'vuex';
	export default {
		data() {
			return {
				key:"",
				category:"",
				goods:[],
				src:"../../../../../static/default_goods.png",
				isShow:true
			}
		},
		computed: mapState(['hasLogin', 'userName','userType']),
		methods: {
			getClicked(id){
				console.log(id);
			}
		},
		onLoad(option) {
			console.log(this.userType);
			let name=option.name;
			let data={};
			let url=''
			if(name=='category'){
				this.category=option.search;
				url='/product/getmore_goodsinfo/';
				data={'category':this.category};
			}else if(name=='search'){
				this.key=option.search;
				url='/users/search_info/'
				data={
					'key':this.key
				};
			}
			console.log(data)
			  this.$myRequest({
				  url:url,
				  data:data
			  }).then(response=>{
				  console.log(response);
				 if(response.data==='缺货啦，联系店家试试吧~'){
					 this.isShow=false;
				 }else{
					 this.goods=response.data
					 let index;
					 for(index=0;index<response.data.length;index++){
					 	let item=response.data[index]
					 	this.$myRequest({
					 		url:'/product/get_pict_url/',
					 		data:{
					 			"id":item['goodsid']
					 		}
					 	}).then(res=>{
					 		if(res.data.length==0){
					 			item.goodspicture=this.src;
					 		}else{
					 			item.goodspicture=res.data[0];
					 		}
					 	})
					 }
				 }
			  })
		},
		onUnload(){
			
		}
	}
</script>

<style lang="scss">
	.temp{
		.temp_text1 {
				width: 100px;
				margin-right: 10px;
			    display: inline-block;
		}
		.temp_text2{
				width: 100px;
				margin-right: 10px;
			    display: inline-block;

		}
		.temp_text3{
			width: 100px;
			margin-right: 10px;
			display: inline-block;
		}
		.temp_text4{
			color: #8F8F94;
			width: 250px;
			margin-right: 10px;
			   display: inline-block;
			   // overflow: hidden；
			   // white-space: nowrap；
			   // text-overflow: ellipsis；
			overflow: hidden;
			-webkit-line-clamp: 1;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
		}
	}
</style>
